﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FisheryPlatform.Search.Core.Analysis
{
    /// <summary>
    /// MMSegment support clases.
    /// using Lecene.Net.SupportClass.
    /// </summary>
    /// <author>gwd, 2006-5-26</author>
    public sealed class MMSupport
    {
        #region MMSupport

        internal static void Debug(string debug)
        {
            System.Diagnostics.Debug.WriteLine(debug);
        }

        /// <summary>
        /// get System.Text.Encoding.Default
        /// </summary>
        /// <returns></returns>
        public static System.Text.Encoding GetEncoding()
        {
            return System.Text.Encoding.Default;
        }

        #endregion MMSupport

        #region SubUnicodeSetSupport

        /*******************************/
        /// <summary>
        /// Support class used to determinate special character sub-sets.
        /// </summary>
        public class SubUnicodeSetSupport
        {
            private string name;

            /// <summary>
            /// Constructs a new SubUnicodeSetSupport instance with the specified name.
            /// </summary>
            /// <param name="name">The name for the new SubUnicodeSet</param>
            protected SubUnicodeSetSupport(string name)
            {
                this.name = name;
            }

            /// <summary>
            /// Overrides System.Object.ToString method.
            /// </summary>
            /// <returns>The name of one UnicodeBlock, or the specified by the user.</returns>
            public override string ToString()
            {
                return this.name;
            }

            /// <summary>
            /// Use this method to compare two SubUnicodeSetSupport objects.
            /// The result of "==" operator is not correct!
            /// </summary>
            /// <param name="obj"></param>
            /// <returns></returns>
            public bool Equals(SubUnicodeSetSupport obj)
            {
                return (this.name == obj.name);
            }

        }

        #endregion SubUnicodeSetSupport

        #region UnicodeSetSupport

        /*******************************/
        /// <summary>
        /// Defines the Unicode 2.0 Characters, and checks if one character correspond to one block.
        /// </summary>
        public sealed class UnicodeSetSupport : SubUnicodeSetSupport
        {
            private UnicodeSetSupport(string name)
                : base(name)
            {
            }

            private static int[] low =
      {
        0x0,    0x80,   0x100,  0x180,  0x250,  0x2B0,  0x300,  0x370,  0x400,  0x530,  0x590,  
        0x600,  0x900,  0x980,  0xA00,  0xA80,  0xB00,  0xB80,  0xC00,  0xC80,  0xD00,  0xE00,  
        0xE80,  0xF00,  0x10A0, 0x1100, 0x1E00, 0x1F00, 0x2000, 0x2070, 0x20A0, 0x20D0, 0x2100, 
        0x2150, 0x2190, 0x2200, 0x2300, 0x2400, 0x2440, 0x2460, 0x2500, 0x2580, 0x25A0, 0x2600, 
        0x2700, 0x3000, 0x3040, 0x30A0, 0x3100, 0x3130, 0x3190, 0x3200, 0x3300, 0x4E00, 0xAC00, 
        0xD800, 0xE000, 0xF900, 0xFB00, 0xFB50, 0xFE20, 0xFE30, 0xFE50, 0xFE70, 0xFF00, 0xFFF0
      };

            private static int[] high =
      {
        0x7F,   0xFF,   0x17F,  0x24F,  0x2AF,  0x2FF,  0x36F,  0x3FF,  0x4FF,  0x58F,  0x5FF,  
        0x6FF,  0x97F,  0x9FF,  0xA7F,  0xAFF,  0xB7F,  0xBFF,  0xC7F,  0xCFF,  0xD7F,  0xE7F,  
        0xEFF,  0xFBF,  0x10FF, 0x11FF, 0x1EFF, 0x1FFF, 0x206F, 0x209F, 0x20CF, 0x20FF, 0x214F, 
        0x218F, 0x21FF, 0x22FF, 0x23FF, 0x243F, 0x245F, 0x24FF, 0x257F, 0x259F, 0x25FF, 0x26FF,  
        0x27BF, 0x303F, 0x309F, 0x30FF, 0x312F, 0x318F, 0x319F, 0x32FF, 0x33FF, 0x9FFF, 0xD7A3, 
        0xDFFF, 0xF8FF, 0xFAFF, 0xFB4F, 0xFDFF, 0xFE2F, 0xFE4F, 0xFE6F, 0xFEFF, 0xFFEF, 0xFFFF
      };

            private static string[] UniNames =
      {
        "BasicLatin", "Latin1Supplement", "LatinExtendedA", "LatinExtendedB", "IpaExtensions",
        "SpacingModifierLetters", "CombiningDiacriticalMarks", "Greek", "Cyrillic", "Armenian",
        "Hebrew", "Arabic", "Devanagari", "Bengali", "Gurmukhi", "Gujararti", "Oriya", "Tamil",
        "Telugu", "Kannada", "Malayalam", "Thai", "Lao", "Tibetan", "Georgian", "HangulJamo",
        "LatinExtendedAdditional", "GreekExtended", "GeneralPuntuaction", "SuperScriptsAndSubScripts",
        "CurrencySymbols", "CombiningMarksForSymbols", "LetterLikeSymbols", "NumberForms",
        "Arrows", "MathematicalOperations", "MiscellaneousTechinal", "ControlPictures",
        "OpticalCharacterRecognition", "EnclosedAlphaNumerics", "BoxDrawing", "BlockElements",
        "GeometricShapes", "MiscellaneousSymbols", "DingBats", "CjkSymbolsAndPunctuation", "Hiragana",
        "Katakana", "Bopomofo", "HangulCompatibilityJamo", "Kanbun", "EnclosedCjkLettersAndMonths",
        "CjkCompatibility", "CjkUnifiedIdeographs", "HagulSyllables", "SurrogatesArea", "PrivateUseArea",
        "CjkCompatibilityIdeographs", "AlphabeticPresentationForms", "ArabicPresentationFormsA",
        "CombiningHalfMarks","CjkCompatibilityForms", "SmallFormVariants", "ArabicPresentationFormsB",
        "HalfWidthAndFullWidthForms", "Specials"
      };

            /// <summary>
            /// Determinates the unicode block that match the specified character.
            /// </summary>
            /// <param name="unicodechar">The unicode character to determinate.</param>
            /// <returns>A new instance of UnicodeSetSupport with the name of the corresponding character 
            /// unicode block.</returns>
            public static UnicodeSetSupport BlockOf(char unicodechar)
            {
                for (int i = 0; i < 66; i++)
                {
                    if ((unicodechar <= high[i]) && (unicodechar >= low[i]))
                        return new UnicodeSetSupport(UniNames[i]);
                }
                return new UnicodeSetSupport("Specials");
            }

            //Unicode Constants for Unicode Blocks.
            public static readonly UnicodeSetSupport BasicLatin = new UnicodeSetSupport("BasicLatin");
            public static readonly UnicodeSetSupport Latin1Supplement = new UnicodeSetSupport("Latin1Supplement");
            public static readonly UnicodeSetSupport LatinExtendedA = new UnicodeSetSupport("LatinExtendedA");
            public static readonly UnicodeSetSupport LatinExtendedB = new UnicodeSetSupport("LatinExtendedB");
            public static readonly UnicodeSetSupport IpaExtensions = new UnicodeSetSupport("IpaExtensions");
            public static readonly UnicodeSetSupport SpacingModifierLetters = new UnicodeSetSupport("SpacingModifierLetters");
            public static readonly UnicodeSetSupport CombiningDiacriticalMarks = new UnicodeSetSupport("CombiningDiacriticalMarks");
            public static readonly UnicodeSetSupport Greek = new UnicodeSetSupport("Greek");
            public static readonly UnicodeSetSupport Cyrillic = new UnicodeSetSupport("Cyrillic");
            public static readonly UnicodeSetSupport Armenian = new UnicodeSetSupport("Armenian");
            public static readonly UnicodeSetSupport Hebrew = new UnicodeSetSupport("Hebrew");
            public static readonly UnicodeSetSupport Arabic = new UnicodeSetSupport("Arabic");
            public static readonly UnicodeSetSupport Devanagari = new UnicodeSetSupport("Devanagari");
            public static readonly UnicodeSetSupport Bengali = new UnicodeSetSupport("Bengali");
            public static readonly UnicodeSetSupport Gurmukhi = new UnicodeSetSupport("Gurmukhi");
            public static readonly UnicodeSetSupport Gujarati = new UnicodeSetSupport("Gujarati");
            public static readonly UnicodeSetSupport Oriya = new UnicodeSetSupport("Oriya");
            public static readonly UnicodeSetSupport Tamil = new UnicodeSetSupport("Tamil");
            public static readonly UnicodeSetSupport Telugu = new UnicodeSetSupport("Telugu");
            public static readonly UnicodeSetSupport Kannada = new UnicodeSetSupport("Kannada");
            public static readonly UnicodeSetSupport Malayalam = new UnicodeSetSupport("Malayalam");
            public static readonly UnicodeSetSupport Thai = new UnicodeSetSupport("Thai");
            public static readonly UnicodeSetSupport Lao = new UnicodeSetSupport("Lao");
            public static readonly UnicodeSetSupport Tibetan = new UnicodeSetSupport("Tibetan");
            public static readonly UnicodeSetSupport Georgian = new UnicodeSetSupport("Georgian");
            public static readonly UnicodeSetSupport HangulJamo = new UnicodeSetSupport("HangulJamo");
            public static readonly UnicodeSetSupport LatinExtendedAdditional = new UnicodeSetSupport("LatinExtendedAdditional");
            public static readonly UnicodeSetSupport GreekExtended = new UnicodeSetSupport("GreekExtended");
            public static readonly UnicodeSetSupport GeneralPunctuation = new UnicodeSetSupport("GeneralPunctuation");
            public static readonly UnicodeSetSupport SuperScriptsAndSubScripts = new UnicodeSetSupport("SuperScriptsAndSubScripts");
            public static readonly UnicodeSetSupport CurrencySymbols = new UnicodeSetSupport("CurrencySymbols");
            public static readonly UnicodeSetSupport CombiningMarksForSymbols = new UnicodeSetSupport("CombiningMarksForSymbols");
            public static readonly UnicodeSetSupport LetterLikeSymbols = new UnicodeSetSupport("LetterLikeSymbols");
            public static readonly UnicodeSetSupport NumberForms = new UnicodeSetSupport("NumberForms");
            public static readonly UnicodeSetSupport Arrows = new UnicodeSetSupport("Arrows");
            public static readonly UnicodeSetSupport MathematicalOperators = new UnicodeSetSupport("MathematicalOperators");
            public static readonly UnicodeSetSupport MiscellaneousTechnical = new UnicodeSetSupport("MiscellaneousTechnical");
            public static readonly UnicodeSetSupport ControlPictures = new UnicodeSetSupport("ControlPictures");
            public static readonly UnicodeSetSupport OpticalCharacterRecognition = new UnicodeSetSupport("OpticalCharacterRecognition");
            public static readonly UnicodeSetSupport EnclosedAlphaNumerics = new UnicodeSetSupport("EnclosedAlphaNumerics");
            public static readonly UnicodeSetSupport BoxDrawing = new UnicodeSetSupport("BoxDrawing");
            public static readonly UnicodeSetSupport BlockElements = new UnicodeSetSupport("BlockElements");
            public static readonly UnicodeSetSupport GeometricShapes = new UnicodeSetSupport("GeometricShapes");
            public static readonly UnicodeSetSupport MiscellaneousSymbols = new UnicodeSetSupport("MiscellaneousSymbols");
            public static readonly UnicodeSetSupport DingBats = new UnicodeSetSupport("DingBats");
            public static readonly UnicodeSetSupport CjkSymbolsAndPunctuation = new UnicodeSetSupport("CjkSymbolsAndPunctuation");
            public static readonly UnicodeSetSupport Hiragana = new UnicodeSetSupport("Hiragana");
            public static readonly UnicodeSetSupport Katakana = new UnicodeSetSupport("Katakana");
            public static readonly UnicodeSetSupport Bopomofo = new UnicodeSetSupport("Bopomofo");
            public static readonly UnicodeSetSupport HangulCompatibilityJamo = new UnicodeSetSupport("HangulCompatibilityJamo");
            public static readonly UnicodeSetSupport Kanbun = new UnicodeSetSupport("Kanbun");
            public static readonly UnicodeSetSupport EnclosedCjkLettersAndMonths = new UnicodeSetSupport("EnclosedCjkLettersAndMonths");
            public static readonly UnicodeSetSupport CjkCompatibility = new UnicodeSetSupport("CjkCompatibility");
            public static readonly UnicodeSetSupport CjkUnifiedIdeographs = new UnicodeSetSupport("CjkUnifiedIdeographs");
            public static readonly UnicodeSetSupport HangulSyllables = new UnicodeSetSupport("HangulSyllables");
            public static readonly UnicodeSetSupport SurrogatesArea = new UnicodeSetSupport("SurrogatesArea");
            public static readonly UnicodeSetSupport PrivateUseArea = new UnicodeSetSupport("PrivateUseArea");
            public static readonly UnicodeSetSupport CjkCompatibilityIdeographs = new UnicodeSetSupport("CjkCompatibilityIdeographs");
            public static readonly UnicodeSetSupport AlphabeticPresentationForms = new UnicodeSetSupport("AlphabeticPresentationForms");
            public static readonly UnicodeSetSupport ArabicPresentationFormsA = new UnicodeSetSupport("ArabicPresentationFormsA");
            public static readonly UnicodeSetSupport CombiningHalfMarks = new UnicodeSetSupport("CombiningHalfMarks");
            public static readonly UnicodeSetSupport CjkCompatibilityForms = new UnicodeSetSupport("CjkCompatibilityForms");
            public static readonly UnicodeSetSupport SmallFormVariants = new UnicodeSetSupport("SmallFormVariants");
            public static readonly UnicodeSetSupport ArabicPresentationFormsB = new UnicodeSetSupport("ArabicPresentationFormsB");
            public static readonly UnicodeSetSupport HalfWidthAndFullWidthForms = new UnicodeSetSupport("HalfWidthAndFullWidthForms");
            public static readonly UnicodeSetSupport Specials = new UnicodeSetSupport("Specials");
        }

        #endregion UnicodeSetSupport

    }
}
